<template>
	<view>
		<view class='header-Container header-height'>
			<view class="header-bg"></view>
			<navHeader pageTitle="我的收藏" rightBtnType="msgCenter" colorTheme="black" @toggleMenuListHandler="toggleMenuListHandler">
			</navHeader>
		</view>
		<view style="height: 20upx;"></view>
		<view v-if="goodsList.length" style="width: 100%;padding: 0 30upx;">
			<goods-across v-for="item in goodsList" :item="item" :key="item.goodsCd" />
		</view>
		<g-empty v-else />
		<view class="" style="height: 60upx;"></view>

		<!-- 详情菜单 -->
		<view v-if="showDetailMenu" @click="toggleMenuListHandler()" class="detailMenu-Container">
			<detailMenu></detailMenu>
		</view>
	</view>
</template>

<script>
	import navHeader from '@/components/nav-header/nav-header';
	import detailMenu from "@/components/detailMenu/detailMenu";
	export default {
		components: {
			navHeader,
			detailMenu
		},
		data() {
			return {
				//详情菜单
				showDetailMenu: false,
				pageNum: 1,
				goodsList: []
			}
		},
		onLoad() {
			this.gerRequest()
		},
		onPullDownRefresh() {
			this.pageNum = 1;
			this.goodsList = []
			this.gerRequest();
		},
		onReachBottom() {
			if (!this.goodsList.length) return;
			this.pageNum += 1;
			this.gerRequest();

		},
		methods: {
			//详情菜单
			toggleMenuListHandler() {
				this.showDetailMenu = !this.showDetailMenu;
			},
			async gerRequest() {
				this.$api.showLoading()
				await this.$api.globalUtil.requestAjax({
					url: '/customerAttentionApi/customerAttentionListApi',
					method: "POST",
					data: {
						caType: 0,
						pageNum: this.pageNum, //页码
						pageSize: 10, //显示条数
					},
					success: (res) => {
						if (!res.data.success) return this.$api.msg(res.data.msg || '获取失败');
						let arr = res.data.response.results || [];
						if (!arr.length && this.pageNum != 1) return this.$api.msg('没有更多了...');
						arr.forEach(item => {
							let priceArr = (item.salesPrice / 100).toFixed(2).split('.');
							item.salesPrice = priceArr[0]
							item.zero = priceArr[1] ? '.' + priceArr[1] : ''
							item.marketPrice = (item.marketPrice / 100).toFixed(2)
							item.goodsLabelArr = item.goodsLabel ? item.goodsLabel.split(',') : []
						})
						console.log(res.data.response.results)
						console.log(this.goodsList)
						this.goodsList = this.goodsList.concat(arr)
					},
					complate: () => (uni.stopPullDownRefresh(), this.$api.hideLoading())
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	/* header部分 */
	.header-Container {
		z-index: 999;
		position: sticky;
		top: 0;
		width: 100%;
		height: 176rpx;
		overflow: hidden;
		box-shadow: 0px 1rpx 1rpx 0px rgba(0, 0, 0, 0.08);
		background: rgba(255, 255, 255, 1);

		.leftBtns {
			display: flex;
			align-items: center;
			justify-content: flex-start;
			position: absolute;
			bottom: 0;
			width: 100%;
			height: 86rpx;

			.back {
				margin-left: 17rpx;
				width: 44rpx;
				height: 44rpx;
			}
		}

		.title {
			position: absolute;
			bottom: 0;
			width: 100%;
			height: 86rpx;
			line-height: 86rpx;
			text-align: center;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: rgba(51, 51, 51, 1);
		}
	}
</style>
